package com.gjy.learning.scala

import org.apache.spark.sql.SparkSession
import org.apache.spark.sql.types._
import org.apache.spark.sql.Row

object ImplicitDemo {
  def main(args: Array[String]): Unit = {

    val spark = SparkSession.builder()
      .appName("DataType Conversion")
      .master("local[*]")
      .getOrCreate()

    import spark.implicits._

    val df = spark.read.csv("src/main/resources/data.csv")
      .toDF("id", "name", "age", "salary")

    // 将age列从字符串类型转换为整数类型
    val newDf = df.withColumn("age", $"age".cast(IntegerType))
      .withColumn("salary", $"salary".cast(DoubleType))

//    newDf.printSchema()
    newDf.show()

    spark.stop()
  }
}
